<template>
  <page-header-wrapper>
    <a-form :model="form" style="width: 200px">
      <a-form-item label="大件物品价格">
        <a-input type="number" step="0.1" v-model="form.bigprice" />
      </a-form-item>

      <a-form-item label="小件物品价格">
        <a-input type="number" step="0.1" v-model="form.smallprice" />
      </a-form-item>

      <a-form-item label="上午接单截止时间">
        <a-time-picker v-model="form.amdeadline" allowClear format="HH:mm" />
      </a-form-item>

      <a-form-item label="下午接单截止时间">
        <a-time-picker v-model="form.pmdeadline" allowClear format="HH:mm"s />
      </a-form-item>

      <a-form-item>
        <a-button type="primary" @click="submitForm('ruleForm')">
          Submit
        </a-button>
      </a-form-item>
    </a-form>
  </page-header-wrapper>

</template>

<script>
import moment from 'moment'
export default {
  name: 'SchoolConfig',
  data () {
    return {
      form: {
        bigprice: '',
        smallprice: '',
        amdeadline: '',
        pmdeadline: ''
      }
    }
  },
  methods: {
    getList () {
      this.fetchList('/schoolconfig/getBySchool').then(data => {
        if (data.data) {
          const am = data.data.amdeadline
          const pm = data.data.pmdeadline
          if (am) {
            data.data.amdeadline = moment(am, 'HH:mm')
          }
          if (pm) {
            data.data.pmdeadline = moment(pm, 'HH:mm')
          }
          this.form = data.data
        }
      })
    },
    submitForm () {
      let am = ''
      if (this.form.amdeadline) {
        am = this.form.amdeadline.format('HH:mm')
      }

      let pm = ''
      if (this.form.pmdeadline) {
        pm = this.form.pmdeadline.format('HH:mm')
      }

      const item = JSON.parse(JSON.stringify(this.form))
      item.amdeadline = am
      item.schoolID = 0
      item.pmdeadline = pm
      this.fetchList('/schoolconfig/updateBySchool', item).then(data => {
        this.getList()
        this.$message.success('更新成功')
      })
    }
  },
  created () {
    this.getList()
  }
}
</script>

<style scoped>

</style>
